"""Href and Menu module"""
from django.conf import settings
from resolve import resolve

def get_mod_func(callback):
	dot = callback.rindex('.')
	return callback[:dot], callback[dot+1:]

def processor(request):
	"""Builds menu using applications specified in config.py
	Saves info needed for href tag

	request -- django HttpRequest object"""
	
	menus = []
	
	view = resolve(request.get_full_path())
	params = view[2]
	for callb in settings.MENU_FUNCTIONS:
		module,function = get_mod_func(callb)
		try:
			func = getattr(__import__(module,[],[],[function]),function)
		except ImportError, e:
			raise MenuBuildError, "Could not import %s. Error was: %s"%(module,str(e))
		except AttributeError, e:
			raise MenuBuildError, "No %s in module %s. Error was: %s"%(func,module,str(e))
		menus += func(request,params)
	return {'ham_menus':menus,'ham_kwargs':view[2],'ham_view':view[0],'ham_args':view[1]}
